package com.mg.persional.service.impl;

import cn.hutool.core.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mg.common.exception.ServiceException;
import com.mg.common.vo.ResponseResult;
import com.mg.common.vo.ResponseStatus;
import com.mg.persional.entity.TbBroadcastVideo;
import com.mg.persional.mapper.TbBroadcastVideoMapper;
import com.mg.persional.service.TbBroadcastVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class TbBroadcastVideoServiceImpl implements TbBroadcastVideoService {
    @Autowired
    TbBroadcastVideoMapper tbvm;

    @Override
    public ResponseResult delTBV(String mtNickName) {
        ResponseResult entity = null;
        String s = tbvm.delTBV(mtNickName);
        if (s != null){
            entity = ResponseResult.ok(s);
        }else {
            entity = ResponseResult.error(ResponseStatus.SERVICE_ERROR);
        }
        return entity;
    }

    @Override
    public ResponseResult<TbBroadcastVideo> updateByName(TbBroadcastVideo tbBroadcastVideo) {

        return null;
    }

    @Override
    public ResponseResult<List<TbBroadcastVideo>> getByBvVhw(String bvVhw) {
        ResponseResult<List<TbBroadcastVideo>> entity = null;
        try {
            List<TbBroadcastVideo> byBvVhw = tbvm.getByBvVhw(bvVhw);
            entity = ResponseResult.ok(byBvVhw);
        }catch (ServiceException e){
            throw new ServiceException();
        }
        return entity;
    }
    //播主视频李的根据时间进行查询
    @Override
    public ResponseResult<List<TbBroadcastVideo>> getByTime(String createTime, String endTime) {
        Page<TbBroadcastVideo> page = new Page<>();
        QueryWrapper<TbBroadcastVideo> tbvQueryWrapper = new QueryWrapper<>();
        page.setPages(1);
        page.setSize(10);

        tbvQueryWrapper.select(TbBroadcastVideo.COL_BV_ID,
                TbBroadcastVideo.COL_BV_PICTURE,
                TbBroadcastVideo.COL_BV_TITLE,
                TbBroadcastVideo.COL_BV_VHW,
                TbBroadcastVideo.COL_BV_TIME,
                TbBroadcastVideo.COL_BV_PLAY_VOLUME,
                TbBroadcastVideo.COL_BV_COM_NUMBER,
                TbBroadcastVideo.COL_BV_CREATE_TIME,
                TbBroadcastVideo.COL_MT_NICKNAME);
        //Page<TbBroadcastVideo> paegs = messageMapper.selectPage(messagePage, messageQueryWrapper);
        Page<TbBroadcastVideo> selectPage = tbvm.selectPage(page, tbvQueryWrapper);
        if (selectPage != null){
            //new PageUtil()
        }
        ResponseResult<List<TbBroadcastVideo>> entity = null;
        try {
            List<TbBroadcastVideo> byTime = tbvm.getByTime(createTime, endTime);
            page.setRecords(byTime);
            entity = ResponseResult.ok(byTime);
        }catch (ServiceException e){
            throw new ServiceException();
        }
        return entity;
    }
}
